﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Text;
using System.Windows.Forms;
using DevExpress.XtraEditors;
using WmsApp.StaticData;
using WmsApp.StaticData.Unity;

namespace WmsApp.UI
{
    public partial class QStoreGoods : DevExpress.XtraEditors.XtraUserControl,IQueryControl
    {
        private BaseGoodsCodeTypeObserver goodsCodeTypeObserver = null;
        public QStoreGoods()
        {
            InitializeComponent();
            try
            {
                DataBinding.Binding.BindStoreGoodsState(this.lookUpEditGoodsState);
                DataBinding.Binding.BindStoreType(this.lookUpEditStoreType);
                DataBinding.Binding.BindUnit(this.lookUpEditUnit);
                DataBinding.Binding.BindingGoodsCodeType(this.lookUpEditGoodsCodeType);
            }
            catch (Exception)
            {
               
            }
        }

        protected override void OnLoad(EventArgs e)
        {
            base.OnLoad(e);
            if (GlobalClass.RunTimeMode)
            {
                var subject = StaticData.GoodsCodeTypeSubjectFactory.GetGoodsCodeTypeSubject();
                goodsCodeTypeObserver = new GoodsCodeTypeObserver("in", subject,
                                                                 lookUpEditGoodsCodeType, this.ParentForm);
                subject.Attach(goodsCodeTypeObserver);
            }
        }

        #region IQueryControl Members

        public string GetCondition()
        {
            string condition = "";
            if (lookUpEditGoodsState.EditValue != null && !String.IsNullOrEmpty(lookUpEditGoodsState.EditValue.ToString()))
            {
                condition += (String.Format(" and  Quantity {0} SafeStoreQty ", lookUpEditGoodsState.EditValue));
            }
            if (this.lookUpEditGoodsCodeType.EditValue != null && !String.IsNullOrEmpty(lookUpEditGoodsCodeType.EditValue.ToString()))
            {
                condition += (String.Format(" and NewGoodsCode ='{0}'", lookUpEditGoodsCodeType.EditValue));
            }
            if (this.lookUpEditStoreType.EditValue != null && !String.IsNullOrEmpty(lookUpEditStoreType.EditValue.ToString()))
            {
                condition += (String.Format(" and StoreTypeCode ='{0}' ", lookUpEditStoreType.EditValue));
            }
            if (this.lookUpEditUnit.EditValue != null && !String.IsNullOrEmpty(lookUpEditUnit.EditValue.ToString()))
            {
                condition += (String.Format(" and UnitCode ='{0}' ", lookUpEditUnit.EditValue));
            }

            if (!String.IsNullOrEmpty(this.textEditLikeNewGoodsName.Text.Trim()) )
            {
                condition += (String.Format(" and NewGoodsName like '%{0}%' ", this.textEditLikeNewGoodsName.Text.Trim()));
            }

            //库位
            if (!String.IsNullOrEmpty(this.textEditStoreLocation.Text.Trim()))
            {
                condition += (String.Format(" and  ExtVarChar8  like '%{0}%' ", this.textEditStoreLocation.Text.Trim()));
            }

            return condition;
        }

        #endregion

        #region IQueryControl Members


        public void AddCustomerCondition(string condition)
        {
            throw new NotImplementedException();
        }

        #endregion
    }
}
